var Readble = require('stream').Readable
var util = require('util')
util.inherits(MyReadable, Readble)
function MyReadable(array) {
  Readble.call(this, {objectMode: true})
  this.array = array
}
MyReadable.prototype._read = function () {
  console.log('___________read in prototype')
  if (this.array && this.array.length) {
    // shift() 方法用于把数组的第一个元素从其中删除,并返回第一个元素的值
    this.push(this.array.pop())
  } else {
    this.push(null)
  }
}

const array = ['a', 'b', 'c', 'd', 'e']
const read = new MyReadable(array)
read.on('data', data => {
  console.log(data)
})
read.on('end', () => console.log('end'))